<?php


namespace app\api\controller\xiluedu;


use app\common\controller\Api;
use app\common\model\xiluedu\Topic AS TopicModel;

class Topic extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    /**
     * 推荐列表
     */
    public function top_lists(){
        $pagesize = $this->request->param('pagesize',6);
        $this->success('查询成功',TopicModel::topLists($pagesize));
    }

    /**
     * 话题列表
     */
    public function lists(){
        $params = $this->request->param('');
        $this->success('查询成功',TopicModel::lists($params));
    }

    /**
     * 话题圈
     */
    public function invitation(){
        #圈子
        $topic_id = $this->request->param('topic_id');
        if(!$topic_id){
            $this->error('非法参数');
        }
        $row = TopicModel::alias('a')
            ->field('a.id,a.name,a.image,a.forum_count,count(distinct(b.user_id)) forumuser_count,SUM(b.fav_count) thumbs_up_count')
            ->join('xiluedu_topic_forum b','b.topic_id=a.id','LEFT')
            ->where('a.status',1)
            ->group('a.id')
            ->where('a.id',$topic_id)
            ->find();
        if($row && !$row->thumbs_up_count){
            $row->thumbs_up_count = 0;
        }

        $this->success('查询成功',$row);
    }

}